<?php
/**
 * <pre>
 * iBoard v1.0
 * 
 * Display forum file
 * </pre>
 * 
 * @copyright	(c) 2010 DiabloStudios
 * @license		GNU Affero GPL v3 or newer
 * @package		PHP-Fusion
 * @subpackage	iBoard
 * @link		http://diablostudios.pl
 * @version     $Id: index.php 12 2011-03-27 16:04:58Z Bartek $
 */

require_once "../../../maincore.php";
require_once THEMES."templates/admin_header.php"; 
 
require_once INFUSIONS."ds_board/includes/main.php";
require_once DSB_LANGDIR."admin_global.php";

require_once DSB_DIR."includes/class_form.php";
require_once DSB_DIR."includes/class_table.php";

if (! checkrights ( "DSB" ) || ! defined ( "iAUTH" ) || $_GET['aid'] != iAUTH) {
	redirect ( "../../../index.php" );
}



// Begin dealing with the modules
$modules_dir = DSB_ADIR."modules";
//$dir = opendir($modules_dir);
$dir = scandir($modules_dir);
foreach($dir as $id => $module)
{
	if(is_file($modules_dir."/".$module) && !in_array($module, array(".", "..")))
	{
        $module = basename($module,'.php');
        $modules[$module] = 1;

	}
    
}


if(strpos($dsb->input['module'], "/") !== false)
{
	$current_module = explode("/", $dsb->input['module'], 2);
}
else
{
	$current_module = explode("-", $dsb->input['module'], 2);
}


// Check if any of the layout generation classes we can override exist in the style file
$classes = array(
	"Table" => "DefaultTable",
	"Form" => "DefaultForm",
	"FormContainer" => "DefaultFormContainer"
);
foreach($classes as $style_name => $default_name)
{
	// Style does not have this layout generation class, create it
	if(!class_exists($style_name))
	{
		eval("class {$style_name} extends {$default_name} { }");
	}
}

if($dsb->input['module'] && isset($modules[$current_module[0]]))
{
	$run_module = $current_module[0];
}
else
{
	$run_module = "index";
}

$action_handler = $run_module."_action_handler";

// Only POST actions with a valid post code can modify information. Here we check if the incoming request is a POST and if that key is valid.
$post_check_ignores = array(
	"example/page" => array("action")
); // An array of modules/actions to ignore POST checks for.

if($dsb->request_method == "post")
{
	if(in_array($dsb->input['module'], $post_check_ignores))
	{
		$k = array_search($dsb->input['module'], $post_check_ignores);
		if(in_array($dsb->input['action'], $post_check_ignores[$k]))
		{
			$post_verify = false;
		}
	}
	
	if($post_verify == true)
	{
		// If the post key does not match we switch the action to GET and set a message to show the user
		if(!isset($dsb->input['my_post_key']) || $dsb->post_code != $dsb->input['my_post_key'])
		{
			$dsb->request_method = "get";
			$page->show_post_verify_error = true;
		}
	}
}

opentable($locale['admin_title']);
$am = array('index','forums','usergroups','settings');
$sum = array_sum($modules);
$width = 100 / $sum;
echo "<table id='nav' class='tbl-border' width='100%' style='margin: 0 auto;'><tr>";
echo "<td class='tbl2 admin_header' colspan='{$sum}'></td>";
echo "</tr><tr>";

$settings_submenu = "
<div style='position: relative;' class='admin-menu-submenu'>
    <ul id='settings_sub' class='tbl-border tbl1' style='padding: 0;margin: 3px 0 0 0;position:absolute;left:0;top:0;width:100%;display:none;'>
        <li>Narzędzia moderacji</li>
        <li>Prefisky wątków</li>
        <li>Pamięć Podręczna</li>
        <li>Przeliczanie i Przebudowa</li>
    </ul>
</div>
";
$forums_submenu = "
<div style='position: relative;' class='admin-menu-submenu'>
    <ul id='forums_sub' class='tbl-border tbl1' style='padding: 0;margin: 3px 0 0 0;position:absolute;left:0;top:0;width:100%;display:none;'>
        <li><a href=''>Ogłoszenia</a></li>
        <li>Moderacja</li>
        <li>Załączniki</li>
    </ul>
</div>
";
$submenus_head = "<script type=\"text/javascript\">\n$(function() {\n";
foreach ($am as $m) {
    $class = $run_module == $m ? "tbl1" : "tbl2";
    $strong = $run_module == $m ? "bold" : "normal";
    if ($m == "forums"){
        $submenu = $forums_submenu;       
    } elseif ($m == "settings") {
        $submenu = $settings_submenu;
    } else { $submenu = NULL; }
    if ($submenu) {
        $submenus_head .= "
    $('ul#{$m}_sub').hide();
	$('td#{$m}_sub_link').hover(
		function () { 
			$('ul#{$m}_sub').show();
		},
		function () {
			$('ul#{$m}_sub').hide();

		}
	);";
    }

    echo "<td id='{$m}_sub_link' class='{$class}' width='{$width}%' style='text-align: center;'><a  style='font-weight: {$strong}' href='".DSB_ADIR."index.php".$aidlink."&amp;module=".$m."'>".$locale[$m.'_module']."</a>".$submenu."</td>";
}

echo "</tr></table>";

$submenus_head .= "});\n</script>\n";
add_to_head($submenus_head);



require $modules_dir."/".$run_module.".php";


closetable();




require_once THEMES."templates/footer.php";
?>